home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / uupc.lzh / uupc / lib.c < prev    next >
C/C++ Source or Header  |  1990-01-16  |  3KB  |  182 lines

  1. /*
  2.  *    lib.c
  3.  *
  4.  *    Amiga Library
  5.  *
  6.  *    $Id: lib.c,v 1.2 90/01/16 10:26:25 crash Exp Locker: crash $
  7.  */
  8.  
  9. #ifndef lint
  10. static char RCSid[] = "$Id: lib.c,v 1.2 90/01/16 10:26:25 crash Exp Locker: crash $";
  11. #endif /* lint */
  12.  
  13. #include <stdio.h>
  14. #include "host.h"
  15.  
  16. #ifndef _U
  17. # include <ctype.h>
  18. #endif /* _U */
  19.  
  20. #ifndef EACCES
  21. # include <errno.h>
  22. #endif /* EACCES */
  23.  
  24. #ifndef NULL
  25. # define NULL 0L
  26. #endif
  27.  
  28. char *index();
  29. char *rindex();
  30.  
  31. MKDIR( path )
  32. char * path;
  33. {
  34.     char * cp = path;
  35.  
  36.     if ( *cp == '\0' )
  37.         return( 0 );
  38.  
  39.     /* see if we need to make any intermediate directories */
  40.     while ( ( cp = index( cp, '/' ) ) != (char *) NULL ) {
  41.         *cp = '\0';
  42.         mkdir( path );
  43.         *cp = '/';
  44.         cp++;
  45.     }
  46.     /* make last dir */
  47.     return( mkdir( path ) );
  48. }
  49.  
  50. CHDIR( path )
  51. char * path;
  52. {
  53.     char * cp = path;
  54.  
  55.     if ( *cp == '\0' )
  56.         return( 0 );
  57.     MKDIR( path );
  58.     /* change to last directory */
  59.     return( chdir( path ) );
  60. }
  61.  
  62. FILE *FOPEN( name, mode, ftype )
  63. char *name;
  64. char *mode;
  65. char ftype;
  66. {
  67.     char *last;
  68.     FILE *results;
  69.  
  70.     /* are we opening for write or append */
  71.  
  72.     FILEMODE( ftype );
  73.     results = fopen( name, mode );
  74.  
  75.     if ( results != (FILE *) NULL || *mode == 'r' )
  76.         return( results );
  77.  
  78.     /* are we opening in sub-directory */
  79.     last = rindex( name, '/' );
  80.  
  81.     /* let's just verify that all sub-dir's exist */
  82.     if ( last != (char *) NULL ) {
  83.         *last = '\0';
  84.         MKDIR( name );
  85.         *last = '/';
  86.     }
  87.     /* now try open again */
  88.     return( fopen( name, mode ));
  89. }
  90.  
  91. int CREAT( name, mode, ftyp )
  92. char *name;
  93. int mode;
  94. char ftyp;
  95. {
  96.     char *last;
  97.     int results;
  98.  
  99.     /* are we opening for write or append */
  100.     FILEMODE( ftyp );
  101.     results = creat( name, mode );
  102.  
  103.     if ( results != -1 )
  104.         return( results );
  105.  
  106.     /* are we opening in sub-directory */
  107.     last = rindex( name, '/' );
  108.  
  109.     /* lets just verify that all sub-dir's exist */
  110.     if ( last != (char *) NULL ) {
  111.         *last = '\0';
  112.         MKDIR( name );
  113.         *last = '/';
  114.     }
  115.     /* now try open again */
  116.     return( creat( name, mode ) );
  117. }
  118.  
  119. extern FILE *logfile;
  120. extern int debuglevel;
  121. extern int remote;
  122.  
  123. #define MASTER 1
  124.  
  125. /*
  126.  *    getargs
  127.  *        breaks up the argument 'line' into fields.  Uses
  128.  *        whitespace as the field delimiters.
  129.  */
  130. int getargs( line, flds )
  131. char *line;
  132. char **flds;
  133. {
  134.     int i = 0;
  135.     char *s;
  136.  
  137.     while ( *line && (*line != '\n')) {
  138.         if ( isspace(*line) ) {
  139.             line++;
  140.             continue;
  141.         }
  142.         *flds++ = line;
  143.         i++;
  144.         while (!isspace(*line) && *line)
  145.             line++;
  146.         if (isspace(*line))
  147.             *line++ = '\0';
  148.     }
  149.     return(i);
  150. }
  151.  
  152.  
  153. /*
  154.  *    prt
  155.  *        prints the argument 'str' using expanded notation, i.e.
  156.  *        CTRL-A prints as ^A, etc.
  157.  */
  158. char *prt(str, len)
  159. register char *str;
  160. register int len;
  161. {
  162.     static char buff[ 512 ];
  163.     register char *p = buff;
  164.     register int i, ch;
  165.  
  166.     for (i=0; i++ < len && p < buff+500; str++) {
  167.         if ((ch = *str & 0xFF) > 0x7E) {
  168.             *p++ = '~';
  169.             ch &= 0x7F;
  170.         }
  171.         if (ch < 0x20) {
  172.             *p++ = '^';
  173.             *p++ = (char) ch + '@';
  174.         } else if (ch == 0x7F)
  175.             *p++ = 'x';
  176.         else
  177.             *p++ = (char) ch;
  178.     }
  179.     *p = '\0';
  180.     return( buff );
  181. }
  182.